//
import {
  tips
} from "./tip";
const app = getApp();
// const http = 'http://127.0.0.1:8080';
const http = 'http://120.78.130.131:8080';

function wxRequest(url, data, callback) {
  let that = this;
  wx.request({
    url: http + url,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'X-Requested-With': 'XMLHttpRequest',
      'userkey': app.globalData.userkey
    },
    method: 'POST',
    data: data,
    success(res) {
      let e = res.data;
      if (res.statusCode == 200) {
        if (e.code=="success"){
          if(e.msg!=''&&e.msg!=null&&e.msg!=undefined){
            tips.toast(e.msg, '', "none");
          }
          typeof callback == "function" && callback(res);
        }else{
          tips.toast(e.msg, '', "none");
        }
      } else if (res.statusCode == 401) {
        // callbackLogin();
        tips.confirm('登录失效，请重新登录！').then(
            function (res) {  //确定
                login();
            }, function (res) {  //取消
        
            });
      } else {
        tips.toast('系统繁忙', '', "none");
      }  //end if
      tips.loaded()
    },
    fail() {
      tips.toast('网络崩溃啦~', '', "none");
      tips.loaded();
    }
  });
};
function login(){
  wx.reLaunch({
    url: '/pages/person/mine'
  })
}
export {
  wxRequest,
  http
}